<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>统一登陆中心SSO</title>
    <link href="https://cdn.bootcss.com/twitter-bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
    <style>
        body {
            min-width: 500px;
            background-image: url("http://pic1.win4000.com/wallpaper/5/57b7f9405d7f3.jpg");
            background-size: 100%;
            background-repeat: no-repeat;
        }
    </style>
</head>
<body>
<h3 style="margin: 30px auto;color: white;text-align: center;">第一代统一登陆系统 <em> v1.0.1</em></h3>
<div style="width: 363px;height: 110px;margin: 40px auto;">
    <div style="width: 360px;float: left;">
        <div style="float: left;line-height: 36px;font-size: 20px;color: white;">账号</div>
        <input id="username" style="float: right;width: 300px;" type="text" class="form-control" placeholder="请输入账号">
    </div>
    <div style="width: 360px;float: left;margin-top: 20px;margin-bottom: 15px;">
        <div style="float: left;line-height: 36px;font-size: 20px;color: white;">密码</div>
        <input id="password" style="float: right;width: 300px;" type="password" class="form-control"
               placeholder="请输入密码">
    </div>
    <div style="width: 150px;margin: 20px auto;">
        <button id="login" type="button" class="btn btn-success">登陆</button>
        <button id="re" type="button" class="btn btn-info" style="margin-left: 20px;">重置</button>
    </div>
</div>
<script>
    $('#login').click(function () {
        var u = $('#username').val()
        if (u == '')
            return alert('账号不能为空')
        var p = $('#password').val()
        if (p == '')
            return alert('密码不能为空')
        $.ajax({
            url: '/api/login',
            type: 'post',
            data: {'username': u, 'password': p},
            success(data) {
                if (data.code == '2000') {
                    var service = getParam('service')
                    if (service == null) {
                        window.location.replace('http://qbccn.com')
                        return
                    }
                    window.location.replace(service + '?access_token=' + data.data.access_token + '&refresh_token=' + data.data.refresh_token)
                } else {
                    alert(data.message)
                }
            }
        })
    });

    $('#re').click(function () {
        $('#username').val('')
        $('#password').val('')
    });

    function getParam(name) {
        var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
        var r = window.location.search.substr(1).match(reg);
        if (r != null) {
            return unescape(r[2]);
        }
        return null;
    }
</script>
</body>
</html>